#!/usr/bin/env python
from glob import glob
import sys
from astropy.io import fits
import os

if os.path.exists(sys.argv[1]+"/dark_stack.fits"):
    os.system("rm "+sys.argv[1]+"/dark_stack.fits")
files = glob(sys.argv[1]+"/*.fits")
for i in range(len(files)):
    if i==0:
        dark = fits.getdata(files[i]).astype(float)
    else:
        dark += fits.getdata(files[i]).astype(float)
dark /= len(files)
fits.writeto("dark_stack.fits",data=dark,overwrite=True)
